CC 		= arm-linux-gcc
LD 		= arm-linux-ld
AR 		= arm-linux-ar
OBJCOPY = arm-linux-objcopy
OBJDUMP = arm-linux-objdump

CFLAG 		:= -Wall -O2 #-fno-strict-aliasing
CPPFLAG		:= -nostdlib -nostdinc -fno-builtin

s_src 		:= $(wildcard *.S)
c_src 		:= $(wildcard *.c)
s_shell 	:= $(shell ls *.S)
c_shell 	:= $(shell ls *.c)
lcd_shell 	:= $(shell ls lcd/*.c)
obj_s 		:= $(patsubst %.S,%.o, $(s_src))
obj_c 		:= $(patsubst %.c,%.o, $(c_src))
obj_lcd_c	:= $(patsubst %.c,%.o, $(lcd_shell))


boot:start.o $(obj_c) lib1funcs.o $(obj_lcd_c)
#$(obj_s) $(obj_c)
#	dispaly something
#	@echo s_src = $(s_src)
#	@echo c_src = $(c_src)
#	@echo s_shell = $(s_shell)
#	@echo c_shell = $(c_shell)
#	@echo obj_s = $(obj_s)
#	@echo obj_c = $(obj_c)
#	@echo uart = $(uart)
#	arm-linux-ld -Ttext 0 $^ -o $@.elf
#	arm-linux-objcopy -O binary -S $@.elf $@.bin
#	arm-linux-objdump -D -m arm $@.elf > $@.dis
#	arm-linux-objdump -D -b binary -m arm $@.bin > $@.bin.dis

	$(LD) -T boot.lds $^ -o $@.elf
	$(OBJCOPY) -O binary -S $@.elf $@.bin
	$(OBJDUMP) -D -m arm $@.elf > $@.dis
	$(OBJDUMP) -D -b binary -m arm $@.elf > $@.bin.dis

%.o:%.S
	$(CC) $(CPPFLAG) $(CFLAG) -c -o $@ $<
1:
	#arm-linux-gcc -nostdlib -c -o $@ $<
%.o:%.c
	$(CC) $(CPPFLAG) $(CFLAG) -c -o $@ $<
2:
	#arm-linux-gcc -nostdlib -c -o $@ $<
uart:$(uart)
#	arm-linux-gcc -nostdlib -c -o led.o led.c
#	arm-linux-gcc -nostdlib -c -o uart.o uart.c
#	arm-linux-gcc -nostdlib -c -o main.o main.c
#	arm-linux-gcc -nostdlib -c -o start.o start.S
#	arm-linux-ld -Ttext 0 start.o led.o uart.o main.o -o uart.elf
#	arm-linux-objcopy -O binary -S uart.elf uart.bin
#	arm-linux-objdump -D uart.elf > uart.dis

clean:
	rm *.bin *.o *.elf *.dis lcd/*.o

.PHONY:clean
